<template>
  <div class="p-t">
    <div class="">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="全部" name="all"></el-tab-pane>
        <el-tab-pane label="待受理" name="wait"></el-tab-pane>
        <el-tab-pane label="已受理" name="successWait"></el-tab-pane>
      </el-tabs>
      <div class="">
        <TableCompEle class="m-t" ref="multipleTable" height="50vh" :tableData="tableData" :tableConfig="tableConfig" :tableAction="tableAction"
          :isSelect="false" :isIndex="true" :isShowPage="true" :queryParams="queryParams" @getPagination="getList"
          @handleSelectionChange="handleSelectionChange"></TableCompEle>
      </div>
    </div>
    <AddComp ref="addRef" @close="getList" />
  </div>
</template>

<script>
import {
  getAppointmentList,
  deleteAppointmentBatch
} from '@/api/yqgx/appointment'
import AddComp from '@/views/Information/serviceManage/makeManage/common/add.vue'
export default {
  components: { AddComp },
  data() {
    return {
      activeName: 'all',
      queryParams: {
        total: 3,
        currentPage: 1,
        pageSize: 10
      },
      allData: [],
      tableData: [
        // {
        //   title: '中国散裂中子源',
        //   need: '模拟的实验环境',
        //   name: '探究物质微观结构的“超级显微镜”',
        //   property: '科研性质',
        //   startTime: '2023-04-01',
        //   endTime: '2024-01-31',
        //   applyName: '管理员',
        //   applyPhone: '010-23543221',
        //   companyName: '广东省科学技术厅',
        //   answer: '受理'
        // },
        // {
        //   title: '全超导托卡马克核聚变实验装置（EAST)',
        //   need: '运行磁约束核聚变',
        //   name: '基于湍动电流自主调节的内部温度垒的深入研究',
        //   property: '科研性质',
        //   startTime: '2023-07-01',
        //   endTime: '2025-01-31',
        //   applyName: '管理员',
        //   applyPhone: '13823427618',
        //   companyName: '中国科学院合肥物质科学研究院',
        //   answer: '受理'
        // },
        // {
        //   title: '北京正负电子对撞机',
        //   need: '探测器电性能测试',
        //   name: '适配BEPCII高计数率运行',
        //   property: '非科研性质',
        //   startTime: '2023-12-01',
        //   endTime: '2024-06-28',
        //   applyName: '管理员',
        //   applyPhone: '010-3459483',
        //   companyName: '中国科学院高能物理研究所',
        //   answer: '不受理'
        // }
      ],
      tableConfig: [
        {
          prop: 'title',
          label: '共享资源名称'
        },
        {
          prop: 'need',
          label: '共享使用需求'
        },
        {
          prop: 'name',
          label: '课题(任务)名称'
        },
        {
          prop: 'property',
          label: '课题(任务)性质'
        },
        {
          prop: 'startTime',
          label: '预约起始时间'
        },
        {
          prop: 'endTime',
          label: '预约结束时间'
        }
      ],
      tableAction: {
        align: () => 'center',
        width: () => String(120),
        operations: [
          {
            label: '查看',
            isLink: true,
            type: 'primary',
            method: row => {
              this.$refs.addRef.show({
                title: '查看服务预约信息',
                isLook: 'look',
                data: row
              })
            }
          },
          {
            label: '删除',
            isLink: true,
            type: 'danger',
            isShow: (row) => {
              return !row.answer
            },
            method: row => {
              this.deleteFun([row.id])
            }
          },
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getAppointmentList().then((res) => {
        this.tableData = res.data
        this.allData = this.tableData
        this.handleClick()
      })
    },
    handleClick() {
      if (this.activeName == "all") {
        this.tableData = this.allData
        this.queryParams.total = this?.tableData?.length ?? 0
      }
      else if (this.activeName == "wait") {
        this.tableData = this.allData.filter(item => !item.answer)
        this.queryParams.total = this?.tableData?.length ?? 0
      }
      else if (this.activeName == "successWait") {
        this.tableData = this.allData.filter(item => item.answer)
        this.queryParams.total = this?.tableData?.length ?? 0
      }
      else {
        this.tableData = this.allData
        this.queryParams.total = this?.tableData?.length ?? 0
      }
    },
    deleteFun(ids) {
      console.log(
        '%c [ ids ]-216',
        'font-size:13px; background:pink; color:#bf2c9f;',
        ids
      )
      this.$confirm(`确定要删除吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteAppointmentBatch(ids).then(() => {
            this.getList()
            this.$message({
              type: 'success',
              message: '删除成功'
            })
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    }
  }
}
</script>

<style lang="less" scoped></style>